package com.hspedu.enum_;

//演示Enum类的各种方法
public class EnumMethod {
    public static void main(String[] args) {
        //使用 Season04 枚举类演示各种方法
        Season04 autumn = Season04.AUTUMN;

        //输出枚举对象名字
        System.out.println(autumn.name());//AUTUMN

        //ordinal() 输出该枚举对象的次序，从0开始编号
        System.out.println(autumn.ordinal());//2

        //从反编译可以看出，values 方法，返回 Season4[]
        //含有定义的所有枚举对象
        Season04[] season04s = Season04.values();
        for (Season04 season04 : season04s) {//增强for循环
            System.out.println(season04);
        }

        //valueOf: 将字符串转换为枚举对象，要求字符串必须为已有的常量名，否则报异常
        Season04 autumn1 = Season04.valueOf("AUTUMN");
        System.out.println("autumn1=" + autumn1);
        System.out.println(autumn == autumn1);//T

        //compareTo: 比较两个枚举常量，比较的就是编号
        //就是把 Season04.AUTUMN 枚举对象的编号与 Season04.SPRING 枚举对象的编号进行比较
        //结果：Season04.AUTUMN.ordinal - Season04.SPRING.ordinal
        System.out.println(Season04.AUTUMN.compareTo(Season04.SPRING));
    }
}


enum Season04 {

    SPRING("春天", "温暖"), SUMMER("夏天", "炎热"),
    AUTUMN("秋天", "凉爽"), WINTER("冬天", "寒冷");

    private String name;
    private String desc;

    private Season04() {
    }

    private Season04(String name, String desc) {
        this.name = name;
        this.desc = desc;
    }

    public String getName() {
        return name;
    }

    public String getDesc() {
        return desc;
    }

    @Override
    public String toString() {
        return "Season02{" +
                "name='" + name + '\'' +
                ", desc='" + desc + '\'' +
                '}';
    }
}